<!DOCTYPE html>
<html class="ui-page-login">
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <title></title>
    <script src="__PUBLIC__/js/jquery.min.js"></script>
    <script src="__PUBLIC__/home/plugins/layer/layer.js"></script>
    <script src="__PUBLIC__/mui/js/mui.min.js"></script>
    <script src="__PUBLIC__/js/angular.js"></script>
    <script src="__PUBLIC__/common.js"></script>
    <link rel="stylesheet" href="__PUBLIC__/mui/css/mui.css" />
    <link rel="stylesheet" href="__PUBLIC__/mui/css/mui.picker.css" />
    <link rel="stylesheet" href="__PUBLIC__/mui/css/mui.poppicker.css" />
    <script src="__PUBLIC__/mui/js/mui.picker.js"></script>
    <script src="__PUBLIC__/mui/js/mui.poppicker.js"></script>
    <style>

        #member-login{
            display: none;
        }
        .area {
            margin: 20px auto 0px auto;
        }

        .mui-input-group {
            margin-top: 10px;
        }

        .mui-input-group:first-child {
            margin-top: 20px;
        }

        .mui-input-group label {
            width: 35%;
            font-size: 15px;
            color: black;

        }

        .mui-input-row label~input,
        .mui-input-row label~select,
        .mui-input-row label~textarea {
            width: 65%;
            font-size: 15px;
            text-indent: 1em;
            color: #333333;
        }

        .mui-input::-webkit-input-placeholder
        {
            text-align: right;

        }
        .enter  .mui-input::-webkit-input-placeholder{
            padding-right: 1.5em;

        }

        .mui-checkbox input[type=checkbox],
        .mui-radio input[type=radio] {
            top: 6px;
        }

        .mui-content-padded {
            margin-top: 25px;
        }

        .mui-btn {
            padding: 10px;
        }

        .link-area {
            display: block;
            margin-top: 25px;
            text-align: center;
        }

        .spliter {
            color: #bbb;
            padding: 0px 8px;
        }

        .oauth-area {
            position: absolute;
            bottom: 20px;
            left: 0px;
            text-align: center;
            width: 100%;
            padding: 0px;
            margin: 0px;
        }

        .oauth-area .oauth-btn {
            display: inline-block;
            width: 50px;
            height: 50px;
            background-size: 30px 30px;
            background-position: center center;
            background-repeat: no-repeat;
            margin: 0px 20px;
            /*-webkit-filter: grayscale(100%); */
            border: solid 1px #ddd;
            border-radius: 25px;
        }

        .oauth-area .oauth-btn:active {
            border: solid 1px #aaa;
        }

        .oauth-area .oauth-btn.disabled {
            background-color: #ddd;
        }

        .login-active {
            background: #f3363a;
        }
        .mui-input-group .enter{
            background: url("__PUBLIC__/images/enter-right.png")no-repeat;!important ;
            background-position: right 1em center;
            background-size: auto 50%;
        }
        a{
            text-decoration: none;

        }
        .mui-radio input[type='radio']:checked:before, .mui-checkbox input[type='checkbox']:checked:before {
            color: #ef373b;
        }

    </style>
    <link rel="stylesheet" href="__PUBLIC__/js/nice-validator-0.10.11/dist/jquery.validator.css" />
    <script src="__PUBLIC__/js/nice-validator-0.10.11/dist/jquery.validator.js"></script>
    <script src="__PUBLIC__/js/nice-validator-0.10.11/dist/local/zh-CN.js"></script>
</head>
<body ng-app="myApp" ng-controller="Ctrl" ng-cloak>
<header class="mui-bar mui-bar-nav" style="background:#f3363a;">
    <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left" style="color: white"></a>
    <h1 class="mui-title login-item" style="color: white">添加银行卡</h1>
</header>
<div class="mui-content" id="user-login" >
    <form class="mui-input-group" method="post" action="" style="margin-top: 0;  background: #efeff4;" data-validator-option="{stopOnError:false, timely:true,theme:'layer'}">

        <div class="mui-input-group">
            <div class="mui-input-row">
                <label>姓名</label>
                <input name="name" type="text" class="mui-input-clear mui-input"  data-rule="required;" placeholder="输入姓名" ng-model="name"/>
            </div>
            <div class="mui-input-row">
                <label>账号</label>
                <input name="account"  type="text" class="mui-input-clear mui-input" data-rule="required;" placeholder="输入账号" ng-model="number"  maxlength="21"/>
            </div>
            <a href="javascript:void (0)">
                <div class="mui-input-row enter">
                    <label>开户行</label>
                    <input name="bank" ng-model="bankname" type="text" id="showUserPicker" data-rule="required;" class="mui-input-clear mui-input" placeholder="选择开户行"  />
                    <input type="hidden" ng-model="bank" id="bankcode">
                </div> </a>
            <div class="mui-input-row">
                <label>支行</label>
                <input  name="branch"  type="text" class="mui-input-clear mui-input" data-rule="required;" placeholder="输入支行" ng-model="branch"/>
            </div>
            <div class="mui-input-row mui-checkbox mui-left">
                <input name="default" type="checkbox" ng-model="default">
                <span style="display: inline-block;line-height: 40px;height: 40px;padding-left: 16%;font-size: 14px" >设置成默认银行卡</span>
            </div>
        </div>
    </form>
    <div class="mui-content-padded">
        <button id="login" class="mui-btn mui-btn-block mui-btn-danger" style="line-height: 1" ng-click="submit()">确定添加</button>
    </div>
    <div class="mui-content-padded oauth-area">
    </div>
</div>
<script>
    var app = getApp('myApp', []);
    app.controller('Ctrl', function ($scope, $http) {
        $scope.checkbox=false;
        $http({
            method: 'POST',
            headers: {'Content-Type': 'application/x-www-form-urlencoded'},
            transformRequest: function (obj) {
                var str = [];
                for (var p in obj) {
                    str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p]));
                }
                return str.join("&");
            },
            url: "/index.php/Home/Account/bankcard"
        }).then(function successCallback(response) {
            //console.log(response.data.data.bank);
            $scope.default = true;
            var data=[];
            for (var x in response.data.data.bank){
                data[x]={};
                data[x]['value']=response.data.data.bank[x].code;
                data[x]['text']=response.data.data.bank[x].val;
            }
            var userPicker = new mui.PopPicker();
            userPicker.setData(data);
            var showUserPickerButton = document.getElementById('showUserPicker');
            var userResult = document.getElementById('userResult');
            showUserPickerButton.addEventListener('tap', function(event) {
                userPicker.show(function(items) {
                    showUserPicker.value = items[0]['text'];
                    document.getElementById('bankcode').value=items[0]['value']
                  /*  expid.value = JSON.stringify(items[0]['value']);*/
                });
            }, false);
        }, function errorCallback(response) {
            errorHandle(response);
        });


        $scope.submit = function () {
            var valida = $('form').trigger("validate").data("validator").isFormValid();//有表单验证的地方用 这个方法
            if (valida) {
                $scope.code = document.getElementById('bankcode').value;
                $scope.bankname = document.getElementById('showUserPicker').value;
                //console.log($scope)
                /*   var data = {expid: $("#expid").val(), express: $("#showUserPicker").val(), sn: $scope.expsn};*/
                $http({
                    method: 'POST',
                    data: $scope,
                    headers: {'Content-Type': 'application/x-www-form-urlencoded'},
                    transformRequest: function (obj) {
                        var str = [];
                        for (var p in obj) {
                            str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p]));
                        }
                        return str.join("&");
                    },
                    url: "/index.php/Home/Account/addbank"
                }).then(function successCallback(response) {
                    //console.log(response)
                    if (response.data.code == -1) {
                        layer.msg(response.data.msg, {time: 1000})
                    }
                    else if (response.data.code == 0) {
                        layer.msg(response.data.data, {time: 1000})
                        setTimeout(function () {
                            window.location.href = "/index.php/Home/agen/cardlist"
                        }, 1500)
                    }
                }, function errorCallback(response) {
                    errorHandle(response);
                });

            }
        }

    });
</script>
</body>
</html>